// vars/dockerBuild.groovy

def call(Map config) {
    REGISTRY_URL = "${config.DOCKER_REGISTER}"
    NAMESPACE = 'hc'
    APP_NAME = "${config.APP_NAME}"
    APP_VERSION = "${config.IMG_VERSION}"
    OPSPATH = "${config.OPS_PATH}"
    println "OPSPATH:"+OPSPATH
    if(config.SNAPSHOT) {         
       APP_VERSION=APP_VERSION + '-SNAPSHOT'
       POM_FILE='pom'
    }
    
    APP_IMAGE = REGISTRY_URL + "/" + NAMESPACE + "-"  + APP_NAME + config.NODE_TYPE + ":" + APP_VERSION
    
    stage('Create Docker Image') {
        dir('./'){
            sh returnStdout: true, script: """
                 docker build -t ${APP_IMAGE} -f ${OPSPATH}/docker/Dockerfile . --build-arg NAMESPACE=${NAMESPACE} --build-arg APP_NAME=${APP_NAME} --build-arg APP_VERSION=${APP_VERSION}          
            """
        }    
    }  

    stage('Push Docker Image') {
        dir('./'){
            sh returnStdout: true, script: """              
                docker push ${APP_IMAGE}                              
            """
        }    
    }
}